/**
 * 商品表jsForInBound
 */

$(function () {
	initialPageForInBound();
	getGridForInBound();
});

function initialPageForInBound() {
	$(window).resize(function() {
		$('#dataGridForInBound').bootstrapTable('resetView', {height: $(window).height()-56});
	});
}

function getGridForInBound() {
	$('#dataGridForInBound').bootstrapTableEx({
		url: '../../product/list?_' + $.now(),
		height: $(window).height()-56,
        clickToSelect: true,
		queryParams: function(params){
			params.name = vm.keyword;
			return params;
		},
		columns: [
			{radio: true},
            {
                field: "num",
                title : '序号',
                align: "center",
                width: 40,
                formatter: function (value, row, index) {
                    //获取每页显示的数量
                    var pageSize=$('#dataGridForInBound').bootstrapTable('getOptions').pageSize;
                    //获取当前是第几页
                    var pageNumber=$('#dataGridForInBound').bootstrapTable('getOptions').pageNumber;
                    //返回序号，注意index是从0开始的，所以要加上1
                    return pageSize * (pageNumber - 1) + index + 1;
                }
            },
            {field : "name", title : "商品名称", width : "150px"},
            {field : "specification", title : "商品规格", width : "100px"},
            {field : "unit", title : "商品单位", width : "100px"},
            {field : "manufacturer", title : "生产厂家", width : "200px"},
            {field : "gmtCreate", title : "创建时间", width : "200px"},
            {field : "gmtModified", title : "修改时间", width : "200px"},
			{title : "操作", formatter : function(value, row, index) {
					var _html = '';
					_html += '<a href="javascript:;" onclick="vm.remove(false,\''+row.id+'\')" title="删除"><i class="fa fa-trash-o"></i></a>';
					return _html;
				}
			}
		]
	})
}

var vm = new Vue({
	el:'#dpLTE',
	data: {
		keyword: null
	},
	methods : {
		loadForInBound: function() {
			$('#dataGridForInBound').bootstrapTable('refresh');
		},
		<!--增加商品维护按钮的功能-->
		addProductDict: function() {
			top.layer.open({
				type : 2,
				id : 'layerFormProductAdd',
				title : '新增商品',
				closeBtn : 1,
				anim: -1,
				isOutAnim: false,
				shadeClose : false,
				shade : 0.3,
				area: ['420px', '350px'],
				content: ['base/product/add.html'],
				btn: ['确定', '取消'],
				success: function(){
				},
				yes: function(){
					top.frames["layerFormProductAdd"].vm.acceptClick();
					setTimeout(function(){reload();}, 1000);
				}
			});
		},
		remove: function(batch, id) {
			var ids = [];
			if (batch) {
				var ck = $('#dataGridForInBound').bootstrapTable('getSelections');
				if (!checkedArray(ck)) {
					return false;
				}
				$.each(ck, function(idx, item){
					ids[idx] = item.id;
				});
			} else {
				ids.push(id);
			}
			$.RemoveForm({
				url: '../../product/remove?_' + $.now(),
				param: ids,
				success: function(data) {
					reload();
				}
			});
		}
	}
});